/*
 * @Author: YuWuChen82 1813109877@qq.com
 * @Date: 2025-07-20
 * @LastEditors: YuWuChen82 1813109877@qq.com
 * @LastEditTime: 2025-07-21
 * @FilePath: \antd-demo\src\router\index.jsx
 * @Description:
 */
import React, { Suspense } from "react";
import { createBrowserRouter, Navigate } from "react-router-dom";

const Layout = React.lazy(() => import("@/pages/Layout"));
const Login = React.lazy(() => import("@/pages/Login"));
const AuthRoute = React.lazy(() => import("@/components/AuthRoute"));
const Home = React.lazy(() => import("@/pages/Home"));
const Article = React.lazy(() => import("@/pages/Article"));
const Publish = React.lazy(() => import("@/pages/Publish"));

const router = createBrowserRouter([
  {
    path: "/",
    element: (
      <Suspense fallback={<div>加载中...</div>}>
        <AuthRoute>
          <Layout />
        </AuthRoute>
      </Suspense>
    ),
    children: [
      {
        path: "",
        element: <Navigate to="home" replace />,
      },
      {
        name: "home",
        path: "home",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Home />
          </Suspense>
        ),
      },
      {
        name: "article",
        path: "article",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Article />
          </Suspense>
        ),
      },
      {
        name: "publish",
        path: "publish",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <Publish />
          </Suspense>
        ),
      },
    ],
  },
  {
    path: "/login",
    element: (
      <Suspense fallback={<div>加载中...</div>}>
        <Login />
      </Suspense>
    ),
  },
]);

export default router;
